<?php

function delete_status($stat_id) {
	// delete semua topics, semua mentions, semua restatus, semua reply, delete statusnya
	db_query('DELETE FROM topics WHERE topic_stat = '.$stat_id);
	db_query('DELETE FROM mentions WHERE mention_stat = '.$stat_id);
	db_query('DELETE FROM status WHERE restat_from = '.$stat_id);
	db_query('UPDATE status SET reply_stat = 0 WHERE reply_stat = '.$stat_id);
	db_query('DELETE FROM status WHERE stat_id = '.$stat_id);
}

if (defined('NO_DIRECT') && !defined('NOT_FROM_DELETE_USER')) {
	if (isset($_GET['i'])) {
		$delete_id = intval($_GET['i']);
		$status = db_result('SELECT stat_id,stat_user FROM status WHERE stat_id = '.$delete_id);
		if ($status === false) {
			// gagal. hapus tweet yg ga nyata
			echo 'gagal. hapus tweet yg ga nyata';
		} else {
			if ($session['user']['user_id'] == $status['stat_user'] || $session['user']['role'] == '2') {
				delete_status($status['stat_id']);
				// berhasil oye oye
				echo 'berhasil oye oye';
			} else {
				// gagal. hapus tweet yg bukan punya dia
				echo 'gagal. hapus tweet yg bukan punya dia';
			}
		}
	}
}
